# -*- coding: utf-8 -*-
# 创建时间：2021/7/16 17:09
from bs4 import BeautifulSoup
import requests
import time, math, random, json
import pymysql
import re

__author__ = 'LuckyHhy'


def main():
    filename = 'data.txt'  # txt文件和当前脚本在同一目录下，所以不用写具体路径

    with open(filename, 'r') as file_to_read:
        while True:
            lines = file_to_read.readline()  # 整行读取数据
            if not lines:
                break
                pass
            # print(lines)
            cont = lines.split()

            lleng = len(cont)
            # print(lleng)
            # print(cont)

            if lleng == 9:
                print("时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[6], cont[8]))
                content = "时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[6], cont[8])
            elif lleng == 7:
                print("时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[4], cont[6]))
                content = "时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[4], cont[6])
            elif lleng == 8:
                print("时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[5], cont[7]))
                content = "时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[6], cont[7])
            elif lleng == 10:
                print("时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[7], cont[9]))
                content = "时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[7], cont[9])
            else:
                print("时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[8], cont[10]))
                content = "时间：{0},CPF：{1},金额：{2}".format(cont[0], cont[8], cont[10])

            # 写入新的文件
            f2 = open('fwrite.txt', 'a')
            f2.write('\n{}'.format(content))
            f2.close()


if __name__ == '__main__':
    main()
